<script>
import SpritAnimate from './components/SpritAnimate'
import switchSiteJs from "@/mixins/switchSite.js"
import IconTitle from "./components/IconTitle"
import Carousel from "./components/carousel"
import CarouselItem from "./components/carousel-item"
import { sliceArray } from "@/utils/index.js"
// import ChangePwd from "@/components/ChangePwd"
export default {
  name: "switchSite",
  mixins: [switchSiteJs],
  components: {
    SpritAnimate,
    IconTitle,
    Carousel,
    CarouselItem
  },
  data() {
    const scale = this.$root.scale || 1
    const bigImg = require("../../assets/images/ga/big1.jpeg")
    const smallImg = require("../../assets/images/ga/small.png")
    return {
      title: "综治中心应用系统",
      showLight1: false,
      showLight2: false,
      showLight3: false,
      showBigPic: false,
      showSmallPic: false,
      bigBackgroundImage: bigImg,
      smallBackgroundImage: smallImg,
      e: scale,
      sourceData: [
        { width: 52 * scale, height: 52 * scale, icon: "video-share", type: "video-share", title: "视频共享平台" },
        { width: 50 * scale, height: 56 * scale, icon: "railway-protection", type: "railway-protection", title: "铁路护路联防系统" },
        { width: 56 * scale, height: 56 * scale, icon: "comprehensive", type: "comprehensive", title: "综治维稳信息系统" },
        { width: 56 * scale, height: 56 * scale, icon: "confict", type: "confict",title: "矛盾纠纷多元化解系统" },
        { width: 52 * scale, height: 56 * scale, icon: "grid-platform", type: "grid-platform", title: "网格化平台服务管理信息系统" }
      ],
      allData: [],
      showData: [],
      showSettingFlag: true,
      settingData: [] // 设置数组
    }
  },
  watch: {
    "siteTypes.length": {
      immediate: true,
      handler() {
        let data = this.sourceData;
        this.siteTypes.forEach(item => {
          data.push(item.sites)
        });
        // 添加默认系统
        // data.push(this.sourceData)
        // 扁平化数组
        data = data.flat()
        let manageData = []
        this.allData = data.map(item => {
          item.title = item.projectName || item.title || ""
          if (item.projectName === "可视化展示系统") {
            item.width = 58 * this.e
            item.height = 58 * this.e
            item.icon = "visual-display"
          } else if (item.projectName === "地图指挥") {
            item.width = 56 * this.e
            item.height = 52 * this.e
            item.icon = "command-control"
            item.title = "指挥调度系统"
          } else if (item.projectName === "重点人员") {
            item.width = 55 * this.e
            item.height = 57 * this.e
            item.icon = "person-control"
            item.title = "重点人员管控系统"
          } else {
            item.width = item.width || 56 * this.e
            item.height = item.height || 56 * this.e
            item.icon = item.icon || "comprehensive"
          }
          if (item.isSiteManager) {
            manageData.push({isManager: true, ...item })
          }
          return item
        })
        // 拆分数组，按8个一组拆分
        this.allData = this.showData = sliceArray(data || [], 8)
        this.settingData = sliceArray(manageData || [], 8)
        console.log(this.allData, this.showData, this.settingData, 'settingData:::::');
        
      }
    }
  },
  methods: {
    destoryTimer() {
      this.timer && clearTimeout(this.timer);
      this.timer = null;
      // this.timer0 && clearTimeout(this.timer0);
      // this.timer0 = null;
      this.timer1 && clearTimeout(this.timer1);
      this.timer1 = null;
    },
    showChangePwd() {},
    // 跳转
    toWebsite(url, type = "") {
      this.jumpUrl(url, type);
    },
    logout() {
      this.handleLogout()
    },
    handleFinish() {
      this.showLight1 = true;
      this.showLight2 = true;
      this.showLight3 = true;
      this.timer = setTimeout(() => {
        this.showBigPic = true;
        this.showSmallPic = true;
      }, 3000)
      this.timer0 = setTimeout(() => {
        this.$refs.bigImg && this.$refs.bigImg.classList.remove("rotate-img");
      }, 6000)
      this.timer1 = setTimeout(() => {
        this.$refs.bigImg && this.$refs.bigImg.classList.add("rotate-img");
        const bigImg = require("../../assets/images/ga/big2.jpeg")
        this.bigBackgroundImage = bigImg
      }, 9000)
    },
    getLightClass(flag) {
      if (flag) {
        return "anim_fade_image"
      } else {
        return "display-none"
      }
    },
    isShowPic(flag) {
      return flag ? "" : "display-none";
    },
    isRotateImg(flag) {
      return flag ? "rotate-img" : ""
    },
    handleSetting(type) {
      console.log(type, 'type::::::')
      if (type === "setting") {
        this.showSettingFlag = false
        this.showData = this.settingData
      } else {
        this.showSettingFlag = true
        this.showData = this.allData
      }
    },
    renderHeader() {
      return <div class="header">
        <div class="logo"></div>
        <div class="title">{this.title}</div>
        <div class="user-box">
          <div>
            { 
              // <i class="icon el-icon-user"></i>
            }
            <span on-click={this.showChangePwd}>欢迎，{ this.userInfo.userName }</span>
          </div>
          {
            this.userInfo.isPlatformManager && this.userInfo.platformSite ?
            <div>
              <i class="icon el-icon-setting"></i>
              <span
                class="span-manager"
                on-click={this.toWebsite.bind(this, this.userInfo.platformSite.manageUrl, 'manager')}
              >{ this.userInfo.platformSite.projectName }</span>
            </div>
            :""
          }
          <div on-click={this.logout} class="exit"></div>
        </div>
      </div>
    },
    renderSetting() {
      if (this.settingData.length) {
        return <div class="site-setting">
          { this.showSettingFlag ? <span class="span-setting" on-click={this.handleSetting.bind(this, 'setting')}><i class="el-icon-setting" on-click={this.handleSetting.bind(this, 'setting')}/>设置</span> :
          <span class="span-back" on-click={this.handleSetting.bind(this, 'back')}><i class="el-icon-circle-check" on-click={this.handleSetting.bind(this, 'back')} />返回</span> }
        </div>
      } else {
        return ''
      }
    },
    renderData(data) {
      return this._l(data, item => {
        if (item.isManager) {
          return <IconTitle icon={ item.icon } title={ item.title } width={ item.width } height={ item.height } isManager={item.isManager} on-click={
            this.toWebsite.bind(this, item.manageUrl, 'manager')}/>
        }
        return <IconTitle icon={ item.icon } title={ item.title } width={ item.width } height={ item.height } isManager={item.isManager} on-click={
          this.toWebsite.bind(this, item.tokenUrl)}/>
      })
    },
    renderBody() {
      return <div class="body">
        <div class="left">
          <SpritAnimate on-finish={this.handleFinish}/>
          <div class={["beam-light1", this.getLightClass(this.showLight1)]}></div>
          <div class={["beam-light2", this.getLightClass(this.showLight2)]}></div>
          <div class={["beam-light3", this.getLightClass(this.showLight3)]}></div>
          <div class={["big-div", this.isShowPic(this.showBigPic), "rotate-img"]}  ref="bigImg">
            <img src={this.bigBackgroundImage} class="big-img"/>
            {
              // <div class={["big-img"]} style={{ 'background-image': `url(${this.path.resolve(__dirname, this.backgroundImageUrl)})` }}></div>
            }
          </div>
          <div class={["small-div", this.isShowPic(this.showSmallPic), "rotate-img"]}>
            {
              // <div class={["small-img"]}></div>
            }
            <img src={this.smallBackgroundImage} class="small-img" />
          </div>
        </div>
        <div class="right">
          <Carousel autoplay={false} direction={'vertical'} arrow="always">
            {
              this._l(this.showData, item => {
                return <CarouselItem>{this.renderData(item)}</CarouselItem>
              })
            }
          </Carousel>
          <div class="angle top-left"></div>
          <div class="angle top-right"></div>
          <div class="angle bottom-left"></div>
          <div class="angle bottom-right"></div>
          {
            this.renderSetting()
          }
        </div>
      </div>
    }
  },
  render() {
    return <div class="ga-switch-site">
      {this.renderHeader()}
      {this.renderBody()}
    </div>
  },
  beforeCreate() {
    this.timer = null;
    // this.timer0 = null;
    this.timer1 = null;
  },
  beforeDestroy() {
    this.destoryTimer()
  }
}
</script>

<style lang="scss">
.ga-switch-site {
  box-sizing: border-box;
  width: 100%;
  height: 1080px;
  background-image: url(~@/assets/images/ga/switch-bg.png);
  background-size: 100% 100%;
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding-top: 54px;
  .header {
    width: 100%;
    height: 67px;
    line-height: 67px;
    position: relative;
    display: flex;
    justify-content: center;
    .logo {
      width: 70px;
      height: 67px;
      background: url(~@/assets/images/ga/logo.png);
      background-size: 100% 100%;
    }
    .title {
      height: 53px;
      font-size: 56px;
      font-family: SourceHanSansCN Regular, SourceHanSansCN Regular-Regular;
      font-weight: 400;
      text-align: center;
      color: #ffffff;
      line-height: 53px;
      letter-spacing: 6px;
      margin-left: 29px;
    }
    .user-box {
      position: absolute;
      top: 0;
      right: 59px;
      display: flex;
      align-items: center;
      div {
        display: inline-block;
        .icon {
          color: #fff;
          font-size: 20px;
          margin-right: 4px;
        }
        span {
          height: 17px;
          opacity: 0.8;
          font-size: 16px;
          font-family: PingFang SC Medium, PingFang SC Medium-Medium;
          font-weight: 500;
          text-align: center;
          color: #ffffff;
          line-height: 16px;
          margin-right: 33px;
        }
        .span-manager {
          cursor: pointer;
        }
      }
      .exit {
        cursor: pointer;
        width: 24px;
        height: 24px;
        background-image: url(~@/assets/images/ga/exit.png);
        background-size: 100% 100%;
      }
    }
  }
  .body {
    display: flex;
    .left {
      width: 1211px;
      height: 862px;
      .big-div {
        position: absolute;
        left: 322px;
        bottom: 488px;
        width: 340px;
        height: 238px;
        background: rgba(255, 255, 255, 0.04);
        border: 1px solid rgba(255, 255, 255, 0.2);
        padding: 18px 16px 18px 20px;
        .big-img {
          width: 304px;
          height: 202px;
          // background: url(~@/assets/images/ga/big1.jpeg);
          // background-size: 100% 100%;
        }
      }
      .small-div {
        position: absolute;
        left: 719px;
        bottom: 428px;
        width: 185px;
        height: 132px;
        background: rgba(255, 255, 255, 0.04);
        border: 1px solid rgba(255, 255, 255, 0.18);
        padding: 12px;
        .small-img {
          width: 160px;
          height: 107px;
          // background: url(~@/assets/images/ga/small.png);
          // background-size: 100% 100%;
        }
      }
      .beam-light1 {
        position: absolute;
        left: 454px;
        bottom: 295px;
        width: 82px;
        height: 132px;
        background: url(~@/assets/images/ga/beam-light1.png);
        background-size: 100% 100%;
      }
      .beam-light2 {
        position: absolute;
        left: 845px;
        bottom: 192px;
        width: 75px;
        height: 122px;
        background: url(~@/assets/images/ga/beam-light2.png);
        background-size: 100% 100%;
      }
      .beam-light3 {
        position: absolute;
        left: 783px;
        bottom: 323px;
        width: 56px;
        height: 91px;
        background: url(~@/assets/images/ga/beam-light3.png);
        background-size: 100% 100%;
      }
    }
    .right {
      position: relative;
      width: 650px;
      height: 820px;
      .angle {
        width: 28px;
        height: 29px;
      }
      .top-left {
        position: absolute;
        top: -15px;
        left: -15px;
        background: url(~@/assets/images/ga/top-left.png);
        background-size: 100% 100%;
      }
      .top-right {
        position: absolute;
        top: -15px;
        right: 75px;
        background: url(~@/assets/images/ga/top-right.png);
        background-size: 100% 100%;
      }
      .bottom-left {
        position: absolute;
        bottom: -15px;
        left: -15px;
        background: url(~@/assets/images/ga/bottom-left.png);
        background-size: 100% 100%;
      }
      .bottom-right {
        position: absolute;
        bottom: -15px;
        right: 75px;
        background: url(~@/assets/images/ga/bottom-right.png);
        background-size: 100% 100%;
      }
      .el-carousel {
        width: 650px;
        height: 820px;
        position: relative;
        display: flex;
        .el-carousel__arrow--left,
        .el-carousel__arrow--right,
        .el-icon-arrow-left,
        .el-icon-arrow-right {
          display: none;
        }
        .el-carousel__container {
          width: 560px;
          height: 820px;
          background: rgba(0, 134, 255, 0.04);
          border-radius: 6px;
          .el-carousel__item {
            // display: flex;
            // flex-wrap: wrap;
            // justify-content: flex-start;
            padding: 26px 0;
          }
        }
        .el-carousel__indicators {
          position: absolute;
          height: 100px;
          top: 290px;
          right: 0px;
          transform: translateY(-50%);
          .el-carousel__indicator {
            .el-carousel__button {
              width: 8px;
              height: 58px;
              background-color: #3672f4;
              opacity: 0.2;
            }
          }
          .is-active {
            .el-carousel__button {
              opacity: 0.9 !important;
            }
          }
        }
      }
      .site-setting {
        position: absolute;
        top: 17px;
        left: 477px;
        display: flex;
        align-items: center;
        cursor: pointer;
        z-index: 1000;
        span {
          font-size: 16px;
          color: #0c79ff;
        }
        .span-setting {
          color: #0c79ff;
        }
        .span-back {
          color: #ffb44a;
        }
        i {
          font-size: 21px;
          margin-right: 8px;
        }
        .el-icon-setting {
          color: #0c79ff;
        }
        .el-icon-circle-check {
          font-size: 21px;
          margin-right: 8px;
          color: #ffb44a;
        }
      }
    }
  }
}
</style>

<style>
@keyframes turnY {
  0% {
    transform: rotateY(0deg);
  }
  100% {
    transform: rotateY(360deg);
  }
}
.rotate-img {
  animation-name: turnY;
  animation-duration: 3s;
  /* animation-delay: 3s; */
  animation-iteration-count: 1;
}

@keyframes myfadeIn {
  0% {
    opacity: 0;
  }
  /* 25% {
    opacity: 0.25;
  }
  50% {
    opacity: 0.5;
  }
  75% {
    opacity: 0.75;
  } */
  100% {
    opacity: 1;
  }
}
.anim_fade_image {
  transition: opacity 5s;
  animation-name: myfadeIn;
  animation-duration: 5s;
  animation-direction: alternate;
}

:root {
  --animate-duration: 3s !important;
  --animate-delay: 3s !important;
  --animation-timing-function: linear;
  --animate-repeat: 1;
}

.display-none {
  display: none;
}
</style>